
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _REGULAR_EXPRESSION_LITERAL_H_
#define _REGULAR_EXPRESSION_LITERAL_H_

// A RegularExpressionLiteral is one of the
// /foo/g type things.
//
// The spec says it is converted to a RegExp object when scanned,
// and there after evaluation of the literal just returns a reference.
//
// My plan is:
// Don't create a RegExp object when scanning.
// The first time the literal is evaluated for use, create the RegExp
// object and return it, but also save a reference to it.
// Any subsequent times the literal is evaluate, just returned the save
// reference. That is, only evaluate the RegExp once.
//
// This was not done for performance reasons, though we might get lucky
// in that it's fatser than parsing the regex during scanning.

#include "Expression.h"

class RegularExpressionLiteral : public Expression
{
public:
    RegularExpressionLiteral(String* pattern, String* flags);
    virtual Value* evaluate(Scope* scope);

private:
    String* m_pattern;
    String* m_flags;

    // m_regexp is NULL until the first time we generate the RegExp object.
    Value* m_regexp;
};

#endif//_REGULAR_EXPRESSION_LITERAL_H_

